package com.fzhucc.modules.expert.controller;

import com.fzhucc.annotation.AnonymousAccess;
import com.fzhucc.annotation.Log;
import com.fzhucc.modules.expert.domain.dto.ExpertReservationOrderDto;
import com.fzhucc.modules.expert.domain.dto.ExpertReservationQueryCriteria;
import com.fzhucc.modules.expert.service.ExpertReservationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
* @author yyg
* @date 2023-10-20
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "专家库:专家预约表管理")
@RequestMapping("/api/expertReservation")
public class ExpertReservationController {

    private final ExpertReservationService expertReservationService;

    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('expertReservation:list')")
    public void exportExpertReservation(HttpServletResponse response, ExpertReservationQueryCriteria criteria) throws IOException {
        expertReservationService.download(expertReservationService.queryAll(criteria), response);
    }

    @GetMapping
    @Log("查询专家预约")
    @ApiOperation("查询专家预约")
    @PreAuthorize("@el.check('expertReservation:list')")
    public ResponseEntity<Object> queryExpertReservation(ExpertReservationQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(expertReservationService.queryAll(criteria,pageable),HttpStatus.OK);
    }

    /*@PostMapping
    @Log("新增专家预约")
    @ApiOperation("新增专家预约")
    @PreAuthorize("@el.check('expertReservation:add')")
    public ResponseEntity<Object> createExpertReservation(@Validated @RequestBody ExpertReservation resources){
        return new ResponseEntity<>(expertReservationService.create(resources),HttpStatus.CREATED);
    }*/

    /*@PutMapping
    @Log("修改专家预约")
    @ApiOperation("修改专家预约")
    @PreAuthorize("@el.check('expertReservation:edit')")
    public ResponseEntity<Object> updateExpertReservation(@Validated @RequestBody ExpertReservation resources){
        expertReservationService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }*/

    @DeleteMapping
    @Log("删除专家预约")
    @ApiOperation("删除专家预约")
    @PreAuthorize("@el.check('expertReservation:del')")
    public ResponseEntity<Object> deleteExpertReservation(@RequestBody Integer[] ids) {
        expertReservationService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    @AnonymousAccess
    @PostMapping
    @Log("专家预约")
    @ApiOperation("专家预约")
    public ResponseEntity<Object> createExpertReservation(@Validated @RequestBody ExpertReservationOrderDto dto){
        return new ResponseEntity<>(expertReservationService.createByH5(dto), HttpStatus.CREATED);
    }


}